package org.quipu.client;

import com.google.gwt.user.client.ui.HTML;
import static com.google.gwt.user.client.ui.HasHorizontalAlignment.ALIGN_LEFT;
import static com.google.gwt.user.client.ui.HasVerticalAlignment.ALIGN_TOP;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import org.quipu.client.events.AppEvent;
import org.quipu.client.events.AppEventBus;
import org.quipu.client.events.AppEventListener;
import org.quipu.client.events.LoginEvent;

public class UserProfilePanel extends AppEventWidget implements AppEventListener {

    private final VerticalPanel vPanel;

    public UserProfilePanel(AppEventBus eventBus, AppCache cache) {
        super(eventBus, cache);
        vPanel = new VerticalPanel();
        vPanel.setHorizontalAlignment(ALIGN_LEFT);
        vPanel.setVerticalAlignment(ALIGN_TOP);
        vPanel.setSpacing(4);
    }

    @Override
    public void init() {
        getEventBus().addListener(LoginEvent.class, this);
        if(getCache().getUser() != null) {
            HTML details = new HTML("login: " + getCache().getUser().getLogin());
            vPanel.add(details);
        }
    }

    @Override
    public void handleEvent(AppEvent event) {
    }

    @Override
    public Widget getWidget() {
        return vPanel;
    }
}
